package logic.facade;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import logic.service.TeacherService;
import vo.IValueObject;
import vo.TeacherVO;

/**
 *
 * @author Alexander
 */
public class TeacherFacade extends Facade {

    public TeacherFacade() {
        setService(new TeacherService());
    }

    @Override
    protected boolean exist(IValueObject vo) {
        return !(super.find(((TeacherVO) vo).getId()) == null);
    }

    public TeacherVO finByName(String nombre, String apellido) {
        EntityManagerFactory emf = null;
        EntityManager em = null;
        TeacherVO profeVO = null;
        try {
            emf = Persistence.createEntityManagerFactory("StunnicusPU");
            em = emf.createEntityManager();
            profeVO = ((TeacherService) getService()).findByName(nombre, apellido, em);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            em.close();
            return profeVO;
        }

    }
}
